<link rel="stylesheet" type="text/css" href="<?=gurl('css');?>/home.css" />
<script type="text/javascript" src="<?=gurl('js');?>/home.js"></script>
<script type="text/javascript" src="<?=gurl('js');?>/jquery.imgareaselect.min.js"></script>
<script type="text/javascript" src="<?=gurl('js');?>/my97/WdatePicker.js"></script>
<script type="text/javascript" src="<?=gurl('js');?>/area.js"></script>
<?php
if(strlen($large_photo_exists)>0){
?>
<script type="text/javascript">
function preview(img, selection) { 
	var scaleX = <?php echo $thumb_width;?> / selection.width; 
	var scaleY = <?php echo $thumb_height;?> / selection.height; 
	
	//$('#thumbnail + div > img').css({ 
	$('#small_file_area > img').css({ 
		width: Math.round(scaleX * <?php echo $current_large_image_width;?>) + 'px', 
		height: Math.round(scaleY * <?php echo $current_large_image_height;?>) + 'px',
		marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px', 
		marginTop: '-' + Math.round(scaleY * selection.y1) + 'px' 
	});
	$('#x1').val(selection.x1);
	$('#y1').val(selection.y1);
	$('#x2').val(selection.x2);
	$('#y2').val(selection.y2);
	$('#w').val(selection.width);
	$('#h').val(selection.height);
	$('#save_thumb').attr("disabled", "");
} 

$(document).ready(function () { 
	$('#save_thumb').click(function() {
		var x1 = $('#x1').val();
		var y1 = $('#y1').val();
		var x2 = $('#x2').val();
		var y2 = $('#y2').val();
		var w = $('#w').val();
		var h = $('#h').val();
		if(x1=="" || y1=="" || x2=="" || y2=="" || w=="" || h==""){
			alert("请先选择上传图片");
			return false;
		}else{
			return true;
		}
	});
}); 

$(window).load(function () { 
	$('#thumbnail').imgAreaSelect({ aspectRatio: '1:<?php echo $thumb_height/$thumb_width;?>', onSelectChange: preview }); 
});

</script>
<?php }?>
<div class="login">
<? if($account):?>
<a href="/home/profile/<?=$account["account_id"];?>"><?=$account["account_username"];?></a><a href="<?=gurl('accounts/logout');?>">退出</a><a href="<?=gurl('about/contact');?>">建议</a>
<? else:?>
<a href="<?=gurl('accounts/');?>">登录</a><a href="<?=gurl('accounts/');?>">注册</a><a href="<?=gurl('about/contact');?>">建议</a>
<? endif;?>
</div>
<div class="w960">
	<div class="w660">
		<div class="smallCon">
			<h1><?=$userinfo["username"];?>的个人主页</h1>
			<? if($isowner):?>
			<ul class="listEdit">
				<li class="sel"><a href="/home/account/<?=$userinfo["id"];?>">个人设置</a></li>
				<li onmouseover="$(this).addClass('sel');" onmouseout="$(this).removeClass('sel');"><a href="/home/profile/<?=$userinfo["id"];?>">我的轻站</a></li>
				<li onmouseover="$(this).addClass('sel');" onmouseout="$(this).removeClass('sel');"><a href="/home/topic/<?=$userinfo["id"];?>">我的话题</a></li>
				<li onmouseover="$(this).addClass('sel');" onmouseout="$(this).removeClass('sel');"><a href="/home/inbox/<?=$userinfo["id"];?>">我的邮箱</a></li>
				<li onmouseover="$(this).addClass('sel');" onmouseout="$(this).removeClass('sel');"><a href="/home/comment/<?=$userinfo["id"];?>">回应我的</a></li>
			</ul>
			<div class="hackbox"></div>
			<h3>修改头像</h3>
			<form name="photo" enctype="multipart/form-data" action="" method="post">
			<p class="cPurple f14px">支持jpeg，gif，png格式，文件最大允许5M</p>
			<div class="upLoad"><input name="image" type="file" style="border:1px solid #CCCCCC; height:25px \0; margin-bottom:4px;"  /> <input name="upload" class="smallKey" type="submit" value="确定" /></div>
			<input type="hidden" name="dosubmit" id="dosubmit" value="1" />
			</form>
			<? if(strlen($thumb_photo_exists)>0){
				$_SESSION['random_key']= "";
				$_SESSION['user_file_ext']= "";
			} elseif(strlen($large_photo_exists)>0){?>
			<div class="imgEdit_l">
				<p class="f14px">原始文件(请拉动虚线框区域控制剪裁区域)</p>
				<div id="file_area" class="imgBox">
					<? if(strlen($large_photo_exists)>0){?><img src="<?=gurl('data');?>/upload_pic/<?php echo $large_image_name.$_SESSION['user_file_ext'];?>" id="thumbnail" /><? } ?>
				</div>
			</div>
			<div class="imgEdit_r">
				<p class="f14px">头像预览(将实际显示的LOGO图片)</p>
				<div id="small_file_area" class="imgLogo">
					<? if(strlen($large_photo_exists)>0){?><img src="<?=gurl('data');?>/upload_pic/<?php echo $large_image_name.$_SESSION['user_file_ext'];?>" alt="" /><? } ?>
				</div>
				<div id="logo_save">
						<form name="thumbnail" action="" method="post">
							<input type="hidden" name="x1" value="0" id="x1" />
							<input type="hidden" name="y1" value="0" id="y1" />
							<input type="hidden" name="x2" value="180" id="x2" />
							<input type="hidden" name="y2" value="180" id="y2" />
							<input type="hidden" name="w" value="180" id="w" />
							<input type="hidden" name="h" value="180" id="h" />
							<input type="hidden" name="dosubmit2" id="dosubmit2" value="1" />						
				</div>
				<p style="height:30px"><input name="upload_thumbnail" id="save_thumb" class="smallKey" onclick="aj_save_userphoto(<?=$userinfo["id"];?>);" type="button" value="保存" /> <em id="save_msg2" class="cDGreen">&nbsp;</em></p>
				</form>
			</div>
			<? } ?>
			<div class="hackbox"></div>
			<h3>修改个人资料</h3>
			<form name="profileform" id="profileform" action="" method="post">
			<ul class="listInfo" style="margin-top: 20px;">
				<li><label>用户名：</label><div><input type="text" name="username" id="username" value="<?=$userinfo["username"];?>" class="hotwebName"></div></li>
            	<li><label>性别：</label><div><input type="radio" <? if($userinfo["gender"] == 1):?> checked <? endif;?> name="gender" id="gender" value="1" />男 <input <? if($userinfo["gender"] == 2):?> checked <? endif;?> type="radio" name="gender" id="gender" value="2" />女</div></li>
                <li><label>生日：</label><div><input type="text" name="birthday" id="birthday" onClick="WdatePicker()" <? if($userinfo['birthday']>0):?> value="<?=strftime('%Y-%m-%d', $userinfo['birthday']);?>"<? endif;?> class="hotwebName"></div></li>
				<li><label>现居地：</label><div><select id="province" onchange="getCities()" style="width:120px;"></select><select id="city" onchange="getCounties()" style="width:120px;"></select><select id="county" style="width:120px;"></select></div></li>
				<li><label>注册邮箱：</label><div><?=$userinfo["email"];?></div></li>
                <li><label>注册日期：</label><div><?=date("Y-m-d",$userinfo["regtime"]);?></div></li>  
                <li><label>兴趣爱好：</label><div><? foreach ($tags as $tag):?><span><input name="tag" id="tag" type="checkbox" <? if(in_array($tag['id'], $tagslist)):?> checked <? endif;?> value="<?=$tag['id'];?>" /><?=$tag['tagname'];?></span><? endforeach;?><p class="cCGray" id="tag_msg">&nbsp;</p></div></li>
                <li><label>简介：</label><div><textarea name="description" id="description" cols="" rows=""><?=$userinfo["description"];?></textarea></div></li>    
			</ul>
			<div class="hackbox"></div>
			<p style="height:30px;padding-left:88px">
				<input type="button" value="保存" class="smallKey" name="" onclick="aj_save_userinfo(<?=$userinfo['id'];?>);"> <em id="save_msg" class="cDGreen">&nbsp;</em>
			</p>
			</form>
            <h3>修改密码</h3>
            <form name="passwordform" id="passwordform" action="" method="post">
            <ul class="listInfo" style="margin-top: 20px;">
            	<li><b>旧密码：</b><div><input name="oldpassword" id="oldpassword" type="password" class="passInput" /></div></li>
               <li><b>新密码：</b><div><input name="newpassword" id="newpassword" type="password" class="passInput" /></div></li>
               <li><b>再次输入新密码：</b><div><input name="newpassword2" id="newpassword2" type="password" class="passInput" /> <input type="button" onclick="aj_save_userpassword(<?=$userinfo['id'];?>);" value="保存" class="smallKey" name=""> <em id="save_msg2" class="cDGreen">&nbsp;</em></div></li> 
            </ul>
            </form>
            <? else:?>
            	<ul class="listEdit">
					<li class="sel"><a href="/home/account/<?=$userinfo["id"];?>">个人资料</a></li>
					<li onmouseover="$(this).addClass('sel');" onmouseout="$(this).removeClass('sel');"><a href="/home/profile/<?=$userinfo["id"];?>">他的轻站</a></li>
					<li onmouseover="$(this).addClass('sel');" onmouseout="$(this).removeClass('sel');"><a href="/home/topic/<?=$userinfo["id"];?>">他的话题</a></li>
				</ul>
	            <div class="blank8"></div>
	            <ul class="listSomeone">
	            	<li><label>用户名：</label><span class="con"><?=$userinfo["username"];?></span><span class="hackbox"></span></li>
	                <li><label>性别：</label><span class="con"><? if($userinfo["gender"] == 1):?>男<? elseif ($userinfo["gender"] == 2):?>女<? endif;?></span><span class="hackbox"></span></li>
	                <li><label>生日：</label><span class="con"><? if($userinfo['birthday']>0):?><?=strftime('%Y年 %m月 %d日 ', $userinfo['birthday']);?><? endif;?></span><span class="hackbox"></span></li>
	                <li><label>现居地：</label><span class="con"><?=$userinfo["province"];?><? if($userinfo["city"] != 'null') { echo $userinfo["city"];}?><? if($userinfo["county"] != 'null') { echo $userinfo["county"];}?></span><span class="hackbox"></span></li>
	                <li><label>上次登录：</label><span class="con"><?=date("Y-m-d",$userinfo["lastlogin"]);?></span><span class="hackbox"></span></li>
	                <li><label>注册时间：</label><span class="con"><?=date("Y-m-d",$userinfo["regtime"]);?></span><span class="hackbox"></span></li>
	                <li><label>兴趣爱好：</label><span class="con">	
	                <? foreach ($usertags as $tag):?><em><?=$tag['tagname'];?></em><? endforeach;?>
	                </span><span class="hackbox"></span></li>
	                <li><label>简介：</label><span class="con">
	                <?=$userinfo["description"];?>
	                </span><span class="hackbox"></span></li>
	            </ul>
            <? endif;?>
		</div>
	</div>
	<script language="javascript" src="/home/right/<?=$userinfo['id'];?>"></script>
	<div class="hackbox"></div>
</div>
<script type="text/javascript">
        $(document).ready(function(){
            getProvinces('<?=$userinfo['province'];?>');
        });
        
        function getProvinces(selected){
            var pro = "";
            for(var i = 0 ; i < provinces.length; i++){
            	if(provinces[i] == selected) {
            		pro += "<option selected value='"+provinces[i]+"'>" + provinces[i] + "</option>";
            	} else {
            		pro += "<option value='"+provinces[i]+"'>" + provinces[i] + "</option>";
            	}
                
            }
            $('#province').empty().append(pro);
            getCities('<?=$userinfo['city'];?>');
        }
        function getCities(selected){
            var proIndex = $('#province').attr('selectedIndex');
            showCities(proIndex, selected);
            getCounties('<?=$userinfo['county'];?>');
        }
        function showCities(proIndex, selected){
            var cit = "";
            if(cities[proIndex] == null || cities[proIndex].length == 0){
                $('#city').empty();
                $('#city').hide();
                return;
            } 
            for(var i = 0 ;i < cities[proIndex].length ; i++){
            	if(cities[proIndex][i] == selected) {
            		 cit += "<option selected value='"+cities[proIndex][i]+"'>" + cities[proIndex][i] + "</option>";
            	} else {
            		 cit += "<option value='"+cities[proIndex][i]+"'>" + cities[proIndex][i] + "</option>";
            	}
            }
            $('#city').show();
            $('#city').empty().append(cit);
        }
        function getCounties(selected){
            var proIndex = $('#province').attr('selectedIndex');
            var citIndex = $('#city').attr('selectedIndex');
            showCounties(proIndex,citIndex,selected);
        }
        function showCounties(proIndex,citIndex,selected){
            var cou = "";
            if(counties[proIndex][citIndex] == null || cities[proIndex].length == 0){
                $('#county').empty();
                $('#county').hide();
                return;
            } 
            for(var i = 0 ;i < counties[proIndex][citIndex].length;i++){
            	if(counties[proIndex][citIndex][i] == selected) {
            		cou += "<option selected value='"+counties[proIndex][citIndex][i]+"'>" + counties[proIndex][citIndex][i] + "</option>";
            	} else {
            		cou += "<option value='"+counties[proIndex][citIndex][i]+"'>" + counties[proIndex][citIndex][i] + "</option>";
            	}
            }
            $('#county').show();
            $('#county').empty().append(cou);
        }
 </script>